{% extends "base.html" %}

{% block title %}决策员工作台 - 协同调度信息系统{% endblock %}

{% block content %}
<div class="row">
    <!-- 待审核分析结果 -->
    <div class="col-md-4">
        <div class="card">
            <div class="card-header">
                <h6 class="mb-0">
                    <i class="fas fa-clock"></i> 待审核分析
                    <span class="badge bg-warning ms-2">{{ pending_analysis|length }}</span>
                </h6>
            </div>
            <div class="card-body">
                {% if pending_analysis %}
                    {% for analysis in pending_analysis %}
                    <div class="card mb-3 border-warning">
                        <div class="card-body">
                            <h6 class="card-title">
                                <i class="fas fa-chart-bar"></i> 
                                {% if analysis.analysis_type == 'threat' %}威胁分析
                                {% elif analysis.analysis_type == 'vulnerability' %}漏洞分析
                                {% elif analysis.analysis_type == 'opportunity' %}机会分析
                                {% elif analysis.analysis_type == 'comprehensive' %}综合分析
                                {% endif %}
                            </h6>
                            <p class="card-text">
                                <small class="text-muted">
                                    <strong>置信度:</strong> 
                                    <span class="badge bg-secondary">
                                        {% if analysis.confidence_level == 'low' %}低
                                        {% elif analysis.confidence_level == 'medium' %}中
                                        {% elif analysis.confidence_level == 'high' %}高
                                        {% endif %}
                                    </span>
                                </small>
                            </p>
                            <p class="card-text">
                                {{ analysis.findings[:100] }}{% if analysis.findings|length > 100 %}...{% endif %}
                            </p>
                            <div class="d-flex justify-content-between align-items-center">
                                <small class="text-muted">
                                    {{ analysis.created_at.strftime('%Y-%m-%d %H:%M') }}
                                </small>
                                <button class="btn btn-sm btn-outline-primary" 
                                        data-bs-toggle="modal" 
                                        data-bs-target="#viewAnalysisModal{{ analysis.id }}">
                                    <i class="fas fa-eye"></i> 查看
                                </button>
                            </div>
                        </div>
                    </div>

                    <!-- 查看分析详情模态框 -->
                    <div class="modal fade" id="viewAnalysisModal{{ analysis.id }}" tabindex="-1">
                        <div class="modal-dialog modal-lg">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title">
                                        {% if analysis.analysis_type == 'threat' %}威胁分析
                                        {% elif analysis.analysis_type == 'vulnerability' %}漏洞分析
                                        {% elif analysis.analysis_type == 'opportunity' %}机会分析
                                        {% elif analysis.analysis_type == 'comprehensive' %}综合分析
                                        {% endif %}
                                    </h5>
                                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                                </div>
                                <div class="modal-body">
                                    <div class="row mb-3">
                                        <div class="col-md-6">
                                            <p><strong>置信度:</strong> 
                                                <span class="badge bg-secondary">
                                                    {% if analysis.confidence_level == 'low' %}低
                                                    {% elif analysis.confidence_level == 'medium' %}中
                                                    {% elif analysis.confidence_level == 'high' %}高
                                                    {% endif %}
                                                </span>
                                            </p>
                                        </div>
                                        <div class="col-md-6">
                                            <p><strong>分析员:</strong> {{ analysis.created_by }}</p>
                                        </div>
                                    </div>
                                    
                                    <h6>分析发现:</h6>
                                    <div class="bg-light p-3 rounded mb-3">
                                        <pre style="white-space: pre-wrap; margin: 0;">{{ analysis.findings }}</pre>
                                    </div>
                                    
                                    <h6>建议措施:</h6>
                                    <div class="bg-light p-3 rounded mb-3">
                                        <pre style="white-space: pre-wrap; margin: 0;">{{ analysis.recommendations }}</pre>
                                    </div>
                                    
                                    {% if analysis.priority_targets %}
                                    <h6>优先目标:</h6>
                                    <div class="bg-light p-3 rounded mb-3">
                                        <pre style="white-space: pre-wrap; margin: 0;">{{ analysis.priority_targets }}</pre>
                                    </div>
                                    {% endif %}
                                    
                                    {% if analysis.suggested_actions %}
                                    <h6>建议行动:</h6>
                                    <div class="bg-light p-3 rounded mb-3">
                                        <pre style="white-space: pre-wrap; margin: 0;">{{ analysis.suggested_actions }}</pre>
                                    </div>
                                    {% endif %}
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-success" 
                                            onclick="approveAnalysis({{ analysis.id }})">
                                        <i class="fas fa-check"></i> 批准
                                    </button>
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    {% endfor %}
                {% else %}
                    <div class="text-center py-4">
                        <i class="fas fa-check-circle fa-2x text-success mb-2"></i>
                        <p class="text-muted mb-0">暂无待审核分析</p>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>

    <!-- 我的指令 -->
    <div class="col-md-4">
        <div class="card">
            <div class="card-header">
                <h6 class="mb-0">
                    <i class="fas fa-gavel"></i> 我的指令
                    <span class="badge bg-info ms-2">{{ orders|length }}</span>
                </h6>
            </div>
            <div class="card-body">
                {% if orders %}
                    {% for order in orders %}
                    <div class="card mb-3 border-info">
                        <div class="card-body">
                            <h6 class="card-title">
                                <i class="fas fa-bullhorn"></i> {{ order.target }}
                            </h6>
                            <p class="card-text">
                                <small class="text-muted">
                                    <strong>类型:</strong> 
                                    {% if order.order_type == 'reconnaissance' %}侦察指令
                                    {% elif order.order_type == 'analysis' %}分析指令
                                    {% elif order.order_type == 'execution' %}执行指令
                                    {% endif %} |
                                    <strong>优先级:</strong> 
                                    <span class="priority-badge priority-{{ order.priority }}">
                                        {% if order.priority == 'low' %}低
                                        {% elif order.priority == 'medium' %}中
                                        {% elif order.priority == 'high' %}高
                                        {% elif order.priority == 'critical' %}紧急
                                        {% endif %}
                                    </span>
                                </small>
                            </p>
                            <p class="card-text">
                                {{ order.objective[:80] }}{% if order.objective|length > 80 %}...{% endif %}
                            </p>
                            <div class="d-flex justify-content-between align-items-center">
                                <small class="text-muted">
                                    {{ order.created_at.strftime('%Y-%m-%d %H:%M') }}
                                </small>
                                <span class="status-badge status-{{ order.status }}">
                                    {% if order.status == 'pending' %}待执行
                                    {% elif order.status == 'executing' %}执行中
                                    {% elif order.status == 'completed' %}已完成
                                    {% elif order.status == 'failed' %}失败
                                    {% endif %}
                                </span>
                            </div>
                        </div>
                    </div>
                    {% endfor %}
                {% else %}
                    <div class="text-center py-4">
                        <i class="fas fa-gavel fa-2x text-muted mb-2"></i>
                        <p class="text-muted mb-0">暂无下达指令</p>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>

    <!-- 执行结果 -->
    <div class="col-md-4">
        <div class="card">
            <div class="card-header">
                <h6 class="mb-0">
                    <i class="fas fa-tasks"></i> 执行结果
                    <span class="badge bg-success ms-2">{{ execution_results|length }}</span>
                </h6>
            </div>
            <div class="card-body">
                {% if execution_results %}
                    {% for result in execution_results %}
                    <div class="card mb-3 border-success">
                        <div class="card-body">
                            <h6 class="card-title">
                                <i class="fas fa-check-circle"></i> 
                                {% if result.result_type == 'success' %}执行成功
                                {% elif result.result_type == 'partial' %}部分成功
                                {% elif result.result_type == 'failed' %}执行失败
                                {% endif %}
                            </h6>
                            <p class="card-text">
                                {{ result.description[:80] }}{% if result.description|length > 80 %}...{% endif %}
                            </p>
                            <div class="d-flex justify-content-between align-items-center">
                                <small class="text-muted">
                                    {{ result.created_at.strftime('%Y-%m-%d %H:%M') }}
                                </small>
                                <button class="btn btn-sm btn-outline-success" 
                                        data-bs-toggle="modal" 
                                        data-bs-target="#viewResultModal{{ result.id }}">
                                    <i class="fas fa-eye"></i> 查看
                                </button>
                            </div>
                        </div>
                    </div>

                    <!-- 查看执行结果详情模态框 -->
                    <div class="modal fade" id="viewResultModal{{ result.id }}" tabindex="-1">
                        <div class="modal-dialog modal-lg">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title">执行结果详情</h5>
                                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                                </div>
                                <div class="modal-body">
                                    <div class="row mb-3">
                                        <div class="col-md-6">
                                            <p><strong>执行结果:</strong> 
                                                {% if result.result_type == 'success' %}执行成功
                                                {% elif result.result_type == 'partial' %}部分成功
                                                {% elif result.result_type == 'failed' %}执行失败
                                                {% endif %}
                                            </p>
                                        </div>
                                        <div class="col-md-6">
                                            <p><strong>执行员:</strong> {{ result.created_by }}</p>
                                        </div>
                                    </div>
                                    
                                    <h6>执行描述:</h6>
                                    <div class="bg-light p-3 rounded mb-3">
                                        <pre style="white-space: pre-wrap; margin: 0;">{{ result.description }}</pre>
                                    </div>
                                    
                                    {% if result.evidence %}
                                    <h6>执行证据:</h6>
                                    <div class="bg-light p-3 rounded mb-3">
                                        <pre style="white-space: pre-wrap; margin: 0;">{{ result.evidence }}</pre>
                                    </div>
                                    {% endif %}
                                    
                                    {% if result.impact_assessment %}
                                    <h6>影响评估:</h6>
                                    <div class="bg-light p-3 rounded mb-3">
                                        <pre style="white-space: pre-wrap; margin: 0;">{{ result.impact_assessment }}</pre>
                                    </div>
                                    {% endif %}
                                    
                                    {% if result.lessons_learned %}
                                    <h6>经验教训:</h6>
                                    <div class="bg-light p-3 rounded mb-3">
                                        <pre style="white-space: pre-wrap; margin: 0;">{{ result.lessons_learned }}</pre>
                                    </div>
                                    {% endif %}
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    {% endfor %}
                {% else %}
                    <div class="text-center py-4">
                        <i class="fas fa-tasks fa-2x text-muted mb-2"></i>
                        <p class="text-muted mb-0">暂无执行结果</p>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>

<!-- 快速操作 -->
<div class="row mt-4">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <h6 class="mb-0">
                    <i class="fas fa-bolt"></i> 快速操作
                </h6>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-3">
                        <div class="d-grid">
                            <a href="{{ url_for('create_order') }}" class="btn btn-primary">
                                <i class="fas fa-plus"></i> 下达新指令
                            </a>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="d-grid">
                            <button class="btn btn-success" onclick="approveAllAnalysis()">
                                <i class="fas fa-check-double"></i> 批量批准分析
                            </button>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="d-grid">
                            <button class="btn btn-info" onclick="viewSystemStatus()">
                                <i class="fas fa-chart-pie"></i> 系统状态
                            </button>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="d-grid">
                            <a href="{{ url_for('logs') }}" class="btn btn-secondary">
                                <i class="fas fa-list"></i> 查看日志
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
function approveAnalysis(analysisId) {
    if (confirm('确定要批准这个分析结果吗？')) {
        // 这里可以添加AJAX请求来批准分析
        alert('分析结果已批准！');
        location.reload();
    }
}

function approveAllAnalysis() {
    if (confirm('确定要批量批准所有待审核的分析结果吗？')) {
        // 这里可以添加AJAX请求来批量批准
        alert('所有分析结果已批准！');
        location.reload();
    }
}

function viewSystemStatus() {
    alert('系统状态功能开发中...');
}
</script>
{% endblock %}
